package cn.cms.chuangjia.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.cms.chuangjia.domain.Article;
import cn.cms.chuangjia.vo.AjaxResult;
import cn.cms.chuangjia.vo.Page;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.cms.chuangjia.service.IArticleService;


/**
 * 文章Controller
 * 
 * @author ruoyi
 * @date 2024-01-18
 */
@RestController
@RequestMapping("/cms/article")
public class ArticleController extends BaseController
{
    @Autowired
    private IArticleService articleService;

    /**
     * 查询文章列表
     */
     @GetMapping("/list")
    public Page<Article> list(Article article)
    {
        startPage();
        List<Article> list = articleService.selectArticleList(article);
        return Page.convert(PageInfo.of(list));
    }

    /**
     * 导出文章列表
     */
   // @PreAuthorize("@ss.hasPermi('article:article:export')")
    //@Log(title = "文章", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Article article)
//    {
//        List<Article> list = articleService.selectArticleList(article);
//        ExcelUtil<Article> util = new ExcelUtil<Article>(Article.class);
//        util.exportExcel(response, list, "文章数据");
//    }

    /**
     * 获取文章详细信息
     */
   // @PreAuthorize("@ss.hasPermi('article:article:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(articleService.selectArticleById(id));
    }

    /**
     * 新增文章
     */
    //@PreAuthorize("@ss.hasPermi('article:article:add')")
    //@Log(title = "文章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Article article)
    {
        return AjaxResult.toAjax(articleService.insertArticle(article));
    }

    /**
     * 修改文章
     */
    ///@PreAuthorize("@ss.hasPermi('article:article:edit')")
    //@Log(title = "文章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Article article)
    {
        return AjaxResult.toAjax(articleService.updateArticle(article));
    }

    /**
     * 删除文章
     */
    ///@PreAuthorize("@ss.hasPermi('article:article:remove')")
    //@Log(title = "文章", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return AjaxResult.toAjax(articleService.deleteArticleByIds(ids));
    }
}
